var uitl = require("../../../../utils/util.js");
//电影详情页js用es6语法
class Movie{
    constructor(url){
        this.url=url;
    }

    getMovieData(cb){
        this.cb=cb;
        uitl.http(this.url, this.processDoubanData.bind(this))
    }

    processDoubanData(data){
        var director = {
            avatar: "",
            name: "",
        }
        if (data.directors[0] != null) {
            if (data.directors[0].avatars != null) {
                director.avatar = data.directors[0].avatars.large;
            }
            director.name = data.directors[0].name;
        }
        var movie = {
            movieImg: data.images ? data.images.large : "",
            country: data.countries[0],
            title: data.original_title,
            wishCount: data.wish_count,
            commentCount: data.comments_count,
            year: data.year,
            genres: data.genres.join("、"),
            star: uitl.public_funtion(data.rating.stars),
            srcor: data.rating.average,
            director: director,
            summary: data.summary,
            casts: uitl.coverMoviesArray(data.casts),
            castsInfo: uitl.coverMoviesInfo(data.casts),
        }
        this.cb(movie);
    }
}

export {Movie}